#ifndef __TabviewPinAssignment_H_
#define __TabviewPinAssignment_H_
#include <QTableView>
#include <QStandardItemModel>




class TabviewPinAssignment:public QTableView{
    Q_OBJECT
  public:

    class Pin{
      
      public:
        Pin(){}

        Pin(const Pin& pin){
          SetParam(pin);
        }

        Pin(const QString& Name,void* v,const QList<QString>& Functions,const QBrush& BgColor){
          
          SetParam(Name,v,Functions,BgColor);

        }

        ~Pin(){}

        void SetParam(const QString& Name,void* v,const QList<QString>& Functions,const QBrush& BgColor){
          
          this->index=-1;
          this->v=v;
          this->name=Name;
          this->Functions=Functions;
          this->bgColor=BgColor;

        }

        void SetParam(const Pin& pin){
          
          this->index=pin.index;
          this->v=pin.v;
          this->name=pin.name;
          this->Functions=pin.Functions;
          this->bgColor=pin.bgColor;

        }

        void SetParam(const Pin&& pin){SetParam(pin);}

        int Index()const{
          return index;
        }

        void SetIndex(int Index){
          index=Index;
        }

        void* V()const{
          return v;
        }

        const QString& Name()const{
          return name;
        }
        QString Name(){
          return name;
        }

        const QList<QString>& FunctionNames()const{
          return Functions;
        }
        
        const QBrush& BgColor()const{
          return bgColor;
        }
        QBrush& BgColor(){
          return bgColor;
        }

        void SetBgColor(QColor color){
          bgColor=QBrush(color);
        }


      private:
        int index;
        void* v;
        QString name;
        QList<QString> Functions;
        QBrush bgColor;


    };
    


    explicit TabviewPinAssignment(QWidget *parent = nullptr);
    ~TabviewPinAssignment();

    void SetSize(int Row,int Column);

    void SetData(QList<Pin*>& Pins);
    void SetData(const Pin& pin,int Row,int Column);
    void SetData(const Pin& pin,int Index){
      int Row=Index/this->Column;
      int Column=Index-Row*this->Column;
      SetData(pin,Row,Column);
    }

    void SetIcon(QIcon& icon){
      this->icon=icon;
    }
    void SetIcon(QIcon&& icon){
      SetIcon(icon);
    }


  signals:
    void triggered(void* v,int Index,bool checked);


  private slots:

    void SlotContextMenu(QPoint pos);
    void triggered(void* v,bool checked);

  private:
    QStandardItemModel* Model;
    Pin* Pins;
    int Row;
    int Column;
    QIcon icon;

};




#endif //__TabviewPinAssignment_H_
